var mongoose = require('mongoose'),
    uuidv4 = require('uuid/v4'),
    Schema = mongoose.Schema;

var verifySchema = new Schema({
    _id: String,
    name: String,
    storeName: String,
    mid: String,
    password: String,
    idcard: String,
    img: String,
    address: String,
    state: Number,
    block: Number,
    submitTime: Date,
    verifyTime: Date,
    msg: String
}, {
        collection: 'verify'
    });

// Indexes

//Auto update last update time
verifySchema.pre('save', function (next) {
    let verify = this;
    verify._id = uuidv4();
    verify.state = 0;
    verify.block = 0;
    verify.submitTime = new Date();
    verify.verifyTime = null;
    verify.msg = null;
    next();
});

verifySchema.pre('update', function (next) {
    let verify = this;
    console.log(verify);
    // verify._id = uuidv4();
    // verify.state = 0;
    // verify.block = 0;
    // verify.submitTime = new Date();
    // verify.verifyTime = null;
    // verify.msg = null;
    next();
});

mongoose.model('Verify', verifySchema);